package org.ihelpuoo.orm.handler;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

import org.ihelpuoo.lang.ObjectUtils;
import org.ihelpuoo.orm.ObjectRule;
import org.ihelpuoo.orm.filter.FieldFilter;

public abstract class ReadNormalFieldHandler extends FieldHandler
{

	public ReadNormalFieldHandler(ObjectProcessor beanHandler)
	{
		super(beanHandler);
	}

	@Override
	protected void processWithoutExceptionHandle(ObjectRule br, Field f, Object src, Object obj,
			FieldFilter actived, FieldFilter locked, String prefix) throws Exception
	{
		Object v = evalObjectValue(br,f,src,prefix);
		v = ObjectUtils.cast(f.getType(),v);
		if (null != v)
		{
			Method setter = ObjectUtils.getSetter(obj.getClass(),f);
			setter.invoke(obj,new Object[]{v});
		}
	}

	protected abstract Object evalObjectValue(ObjectRule r, Field f, Object src, String prefix)
			throws Exception;

}
